﻿using System.Windows;

namespace CodeLines
{
    /// <summary>
    /// StatusView.xaml 的交互逻辑
    /// </summary>
    public partial class StatusView
    {
        public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
            nameof(State), 
            typeof(RunState), 
            typeof(StatusView),
            new PropertyMetadata(default(RunState),PropertyChanged));

        private static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is StatusView sv)) return;
            if (!(e.NewValue is RunState state)) return;
            sv.ImagePending.Visibility = sv.ImageComplete.Visibility = sv.ImageError.Visibility =
                sv.ProgressBarRunning.Visibility = Visibility.Collapsed;
            switch (state)
            {
                case RunState.Pending:
                    sv.ImagePending.Visibility = Visibility.Visible;
                    break;
                case RunState.Running:
                    sv.ProgressBarRunning.Visibility = Visibility.Visible;
                    break;
                case RunState.Error:
                    sv.ImageError.Visibility = Visibility.Visible;
                    break;
                case RunState.Complete:
                    sv.ImageComplete.Visibility = Visibility.Visible;
                    break;
            }
        }

        public RunState State
        {
            get => (RunState)GetValue(StateProperty);
            set => SetValue(StateProperty, value);
        }

        public StatusView()
        {
            InitializeComponent();
        }
    }
}
